package object3D;

import context.*;

import geometry3D.Point3D;

import model2D.Model2D;
import object2D.MassivTrappProjection;

import java.awt.Color;

import javax.media.j3d.Appearance;
import javax.media.j3d.Group;

import org.json.JSONException;

// ***************************************************************************
// *** CLASS: MassivTrapp
// ***************************************************************************
public class MassivTrapp extends Block implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  public static final Color murFarge=Color.lightGray;

  public static final double oppTrinn=0.18;
  public static final double innTrinn=0.25;

  private static final int maxTrinn=15;
  public Block trinn[]=new Block[maxTrinn];
  public Block trinnOpp[]=new Block[maxTrinn];

  public int kind;
  
  public MassivTrapp(String ident,Point3D p0,double width,double height,double depth,int kind)
  { super(ident,p0,width,height,depth);
    this.kind=kind;
    int n=(int)(width/innTrinn);
    switch(kind)
    { case NORTH: for(int i=0;i<n;i++)
      { trinn[i]=new Block("Trinn",p0.addY(height-oppTrinn*i-0.05).addZ(innTrinn*i-0.05),depth,0.05,innTrinn+0.05);
        trinnOpp[i]=new Block("OppTrinn",p0.addY(height-oppTrinn*(i+1)-0.05+0.05).addZ(innTrinn*(i+1)-0.05),depth,oppTrinn-0.05,0.001);
      } break;
      case SOUTH: for(int i=0;i<n;i++)
      { trinn[i]=new Block("Trinn",p0.addY(height-oppTrinn*(n-1-i)-0.05).addZ(innTrinn*i),depth,0.05,innTrinn+0.05);
        trinnOpp[i]=new Block("OppTrinn",p0.addY(height-oppTrinn*(n-i)-0.05+0.05).addZ(innTrinn*(i)+0.05),depth,oppTrinn-0.05,0.001);
      } break;
      case WEST:  for(int i=0;i<n;i++)
      { trinn[i]=new Block("Trinn",p0.addY(height-oppTrinn*i-0.05).addX(innTrinn*i),innTrinn+0.05,0.05,depth);
        trinnOpp[i]=new Block("OppTrinn",p0.addY(height-oppTrinn*(i+1)).addX(innTrinn*(i+1)),0.001,oppTrinn-0.05,depth);
      } break;
      case EAST:  for(int i=0;i<n;i++)
      { trinn[i]=new Block("Trinn",p0.addY(height-oppTrinn*(n-1-i)-0.05).addX(innTrinn*i),innTrinn+0.05,0.05,depth);
        trinnOpp[i]=new Block("OppTrinn",p0.addY(height-oppTrinn*(n-i)).addX(innTrinn*(i)+0.05),0.001,oppTrinn-0.05,depth);
      } break;
    }
  }
    
  // ***************************************************************************
  // *** METHOD: getModel3D
  // ***************************************************************************
  public /*abstract*/ Group getModel3D(Appearance appearance)
  { Group tg=new Group();
    for(int i=0;i<maxTrinn;i++)
    {
      if(trinn[i]!=null) tg.addChild(trinn[i].getModel3D(appearance));
      if(trinnOpp[i]!=null) tg.addChild(trinnOpp[i].getModel3D(appearance));
      }
    return(tg);
  }  


  // ***************************************************************************
  // *** METHOD: addProjection  (2D)
  // ***************************************************************************
  // 3D ==> 2D projections the XZ, XY or ZY-plane
  public void addProjection(Model2D objectModel,int type,int direction,Color color,float opacity)
  throws JSONException
  { objectModel.addChild(new MassivTrappProjection(objectModel,this,type,direction,color,opacity)); }

}
